<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0" />
    <title>美策平台</title>
    <link rel="icon" type="image/png" href="/img/icon.png">
    <link rel="stylesheet" type="text/css" href="../datepicker/jquery-ui.min.css">
    <link rel="stylesheet" type="text/css" href="../css/app.css">
    <link rel="stylesheet" type="text/css" href="../css/order.css">
    <script type="text/javascript" src="../js/jquery.min.js"></script>
    <script type="text/javascript" src="/pc/js/all.js"></script>
    <script src="http://g.tbcdn.cn/mtb/lib-flexible/0.3.4/??flexible_css.js,flexible.js"></script>
</head>
<body>

<!----------抢单详情页面---------->
<div id="orderParamPage">
    <div id="orderParamTitle">
        <b>公司订单参数</b>
        <img src="../images/return.png" id="orderRtn">
    </div>
    <div style="height:1.066667rem"></div>
    <div id="orderParamAddress">
    </div>
    <div id="orderParamIntro">
    </div>
    <div id="orderParamList">
           <p class="title">订单详情</p>
           <ul class="content orderParamList">
           </ul>
    </div>
    <div id="orderParamBtn">
        <p class="none">订单的30%作为保证金额度</p>
        <div class="button">
            <div class="apply none"  >支付抢单保证金</div>
            <div class="submit qiangdan none"  >立即抢单</div>
        </div>
    </div>
</div>
<!----------订单参数页面---------->

<!----------错误提示---------->
<div id="errMsg"></div>
<!----------错误提示---------->
</body>
<link rel="stylesheet" type="text/css" href="/h5/css/all.css">
<script type="text/javascript" src="../js/getPageId.js"></script>
<script type="text/javascript" src="../js/app.js"></script>
<script type="text/javascript" src="../js/orderPageChange.js"></script>
<script type="text/javascript" src="../js/order.js"></script>
<script type="text/javascript" src="../js/alertMsg.js"></script>
</html>
<script>
    var id = localStorage.getItem('orderShowId');
    var userInfo = JSON.parse(localStorage.getItem('userInfo'));
    var app_access = userInfo.app_access;
    var token = userInfo.token;
    function confirmOrder() {
        var data = {
            id: pageId,
            app_access: app_access,
            token: token
        }
        $.ajax({
            url: '/api/order/bale/confirm-graporder',
            data: data,
            type: 'post',
            dataType: 'json',
            success: function(data) {
                if(data.code < 0){
                    alertMsg(data.msg)
                }else{
                    alertMsg(data.msg)
                    window.location.href='orderDocking.html'
                }
            },
            err: function(err) {
                alertMsg(err)
            }
        })
    }
    function payOrder() {
        var data = {
            id: pageId,
            app_access: app_access,
            token: token
        }
        $.ajax({
            url: '/api/order/bale/payorder',
            data: data,
            type: 'post',
            dataType: 'json',
            success: function(data) {
                if(data.code == 0){
                    window.location.href='orderPayType.html?id='+pageId
                }else{
                    alertMsg(data.msg)
                }
            },
            err: function(err) {
                alertMsg(err)
            }
        })
    }
    $('#orderRtn').on('click', function () {
        window.location.href='orderShow.html?id='+pageId
    })
    $(function() {
        getOrderId();
        function getOrderId() {
            var data = {
                id: MC.get('id'),
                app_access: app_access,
                token: token
            }
            $.ajax({
                url: '/api/order/bale/grapdetail2',
                data: data,
                type: 'post',
                dataType: 'json',
                success: function(data) {
                    var item = data.data;
                    if(data.code != 0){
                        alertMsg(data.msg)
                    }
                    addressHtml = "<div class=\"nameAndPhone\"><div><span class=\"title\">抢单定位:</span><span class=\"content\">"+item.factory.com_name+"</span></div>";
                        if(item.factory.com_tel){
                            addressHtml+="<div>"+item.factory.com_tel+"</div></div>";
                        }

                    addressHtml+="<div class=\"address\"><span class=\"title\">单位地址:</span><span class=\"content\">"+item.factory.com_address+"</span></div>";
                    $("#orderParamAddress").html(addressHtml);

                    infoHtml = "<div class=\"img\"><img src="+item.img+"></div>"+
                               "<div class=\"content\">"+item.detail+"</div>";
                    $("#orderParamIntro").html(infoHtml);

                    var bondspan="￥"+item.bond+"元";
                    if(item.is_rob==2){
                        bondspan="免保证金";
                    }
                    listHtml = "<li>\n" +
                        "                    <span>订单数量</span>\n" +
                        "                    <div>"+item.num+"件</div>\n" +
                        "                </li>\n" +
                        "                <li>\n" +
                        "                    <span>订单金额</span>\n" +
                        "                    <div>￥"+item.money+"元</div>\n" +
                        "                </li>\n" +
                        "                <li>\n" +
                        "                    <span>保证金</span>\n" +
                        "                    <div>"+bondspan+"</div>\n" +
                        "                </li>\n" +
                        "                <li>\n" +
                        "                    <span>厂家备注</span>\n" +
                        "                    <div><input type=\"text\" class=\"bz\" value='"+item.notes+"' placeholder=\"请填写备注\"></div>\n" +
                        "                </li>\n" +
                        "                <li>\n" +
                        "                    <span>下单时间</span>\n" +
                        "                    <div>"+item.createTime+"</div>\n" +
                        "                </li>\n";
                        /*"                <li>\n" +
                        "                    <span>快递运单</span>\n" +
                        "                    <div>"+item.orderNo+"</div>\n" + 
                        "                </li>" +*/
                      /*  "\n" +
                        "                <li>\n" +
                        "                    <span>快递类型</span>\n" +
                        "                    <div>"+item.orderTypeName+"</div>\n" +
                        "                </li>";*/
                    $(".orderParamList").html(listHtml);
                    $('.qiangdan').show();


                    $('.qiangdan').click(function(){

                        MC.click(function(){
                            var msg='该订单为抢单,需要支付保证金'+bondspan+';确定需要抢单吗?';
                            if(item.is_rob==2){
                                msg='该订单为普通订单,不用支付保证金;确定需要抢单吗?';
                            }
                            MC.msg.confirm(msg,function(){
                                    MC.api('ConfirmPayOrder',{
                                        id:MC.get('id'),
                                        notes:$('.bz').val()
                                    },function(json){
                                        // console.log(json);
                                        window.open('/h5/order/orderDocking.html?out_trade_no=' + json.out_trade_no, '_self');
                                        //window.open('/h5/order/orderPayType.html?out_trade_no='+json.out_trade_no,'_self');
                                    });
                            });

                        });

                       /// window.open('/h5/order/orderPayType','_self');


                    });



                },
                err: function(err) {
                    alertMsg(err)
                }
            })
        }
    })
</script>